package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.annotation.AutoFillUserId;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.ShoppingCart;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     *查询当前商品是否在购物车
     * @param shoppingCart
     */
    @AutoFillUserId(OperationType.ADDVALUETOOBJECT)
    List<ShoppingCart> getShopByShoppingCart(ShoppingCart shoppingCart);

    /**
     * 修改数量
     * @param shoppingCart
     */
    @Update("update shopping_cart set  number=#{number} where id=#{id}")
    void updateNumberById(ShoppingCart shoppingCart);

    /**
     * 新增商品到购物车
     * @param shoppingCart
     */
    void insert(ShoppingCart shoppingCart);

    /**
     * 查看购物车
     * @return
     */
    @Select("select * from shopping_cart where user_id=#{userId}")
    @AutoFillUserId(value = OperationType.ADDARG)
    List<ShoppingCart> showShoppingCart(Long userId);

    /**
     * 清空购物车
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id=#{userId}")
    @AutoFillUserId(OperationType.ADDARG)
    void deleteShoppingCart(Long userId);

    /**
     * 根据id删除购物车数据
     * @param id
     */
    @Delete("delete from shopping_cart where id=#{id}")
    void deleteById(Long id);

    /**
     * 批量插入购物车数据
     * @param shoppingCartList
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
